package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.SetmealDto;
import com.itheima.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    @PostMapping
    public R add(@RequestBody SetmealDto setmealDto) {
        R r = setmealService.add(setmealDto);
        return r;
    }

    @GetMapping("/page")
    public R findpage(Integer page, Integer pageSize, String name) {
        R r = setmealService.findpage(page, pageSize, name);
        return r;
    }

    @DeleteMapping
    public R remove(Long[] ids) {
        setmealService.removeIds(ids);
        return R.success("删除成功");
    }

    @PostMapping("/status/{id}")
    public R modifyStatus(Long[] ids, @PathVariable Integer id) {
        setmealService.modifyStatus(ids, id);
        return R.success("操作成功");
    }

    @GetMapping("/{id}")
    public R findById(@PathVariable Long id) {
        R r = setmealService.findById(id);
        return r;
    }

    @PutMapping
    public R update(@RequestBody SetmealDto setmealDto) {
        setmealService.update(setmealDto);
        return R.success("修改成成功");
    }

    @GetMapping("/list")
    public R list(Long categoryId, Integer status) {
       R r = setmealService.list(categoryId, status);
        return r;
    }
}
